package it.polimi.jita.cp.block;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.apache.commons.csv.CSVRecord;
import org.jfree.chart.JFreeChart;

public class Output {

	// CSVRecord for file
	private final Set<List<CSVRecord>> csvFiles = new HashSet<>();
	private final Map<List<CSVRecord>, CSVRecord> headers = new HashMap<>();

	// Charts to show
	private final Set<JFreeChart> charts = new HashSet<>();

	protected void addCsvFile(List<CSVRecord> records) {
		addCsvFile(records, null);
	}

	protected void addCsvFile(List<CSVRecord> records, CSVRecord header) {
		csvFiles.add(records);
		if (header != null)
			headers.put(records, header);
	}

	protected void addJFreeChart(JFreeChart chart) {
		charts.add(chart);
	}

	public Set<List<CSVRecord>> getCSVRecordsWithHeader() {
		Set<List<CSVRecord>> set = new HashSet<>();
		for (List<CSVRecord> csvFile : csvFiles) {
			List<CSVRecord> list = new ArrayList<>(csvFile);
			CSVRecord header = headers.get(csvFile);
			list.add(0, header);
			set.add(list);
		}
		return set;
	}

	public Set<List<CSVRecord>> getCSVRecords() {
		return new HashSet<>(csvFiles);
	}

	public Set<JFreeChart> getCharts() {
		return new HashSet<>(charts);
	}

	protected boolean isWithCharts() {
		return !charts.isEmpty();
	}

	protected boolean isWithCsvFiles() {
		return !csvFiles.isEmpty();
	}

}
